﻿namespace Digitalmes.ApiService.Hubs;

/// <summary>
/// 数据通信 Hub 客户端
/// </summary>
public interface IChannelClient
{
    /// <summary>
    /// 客户端接收服务器端消息
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    Task ReceiveMessage(ClentMessage message);

    /// <summary>
    /// 客户端接收服务器端发送的上料数据
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    Task ReceiveFeeding(ClentMessage message);
}

/// <summary>
/// 服务端传给客户端的数据。
/// </summary>
public sealed class ClentMessage
{
    public DateTime Time { get; } = DateTime.Now;

    /// <summary>
    /// 产线编号
    /// </summary>
    public string? LineCode { get; set; }

    /// <summary>
    /// 产线代码
    /// </summary>
    public string? OpCode { get; set; }

    /// <summary>
    /// SN
    /// </summary>
    public string? Sn { get; set; }

    /// <summary>
    /// 扫关键物料和批次料时有效
    /// </summary>
    public string? Barcode { get; set; }

    /// <summary>
    /// 服务端处理后的状态
    /// </summary>
    public int State { get; set; }

    /// <summary>
    /// 服务端返回的错误消息，没有则为 null。
    /// </summary>
    public string? ErrorMessage { get; set; }

    /// <summary>
    /// 内部错误代码。
    /// </summary>
    public int InnerErrorCode { get; set; }

    /// <summary>
    /// 数据模式，如 进站、出站、扫关键物料、扫批次料、上料等
    /// </summary>
    public string? Mode { get; set; }

    /// <summary>
    /// 数据
    /// </summary>
    public object? Target { get; set; }
}
